home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / xml / gnome / xslt / gettext / l10n-numbers.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2009-03-17  |  14.4 KB  |  391 lines

  1. <?xml version='1.0' encoding='UTF-8'?><!-- -*- indent-tabs-mode: nil -*- -->
  2. <!--
  3. This program is free software; you can redistribute it and/or modify it under
  4. the terms of the GNU Lesser General Public License as published by the Free
  5. Software Foundation; either version 2 of the License, or (at your option) any
  6. later version.
  7.  
  8. This program is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10. FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  11. details.
  12.  
  13. You should have received a copy of the GNU Lesser General Public License
  14. along with this program; see the file COPYING.LGPL.  If not, write to the
  15. Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  16. 02111-1307, USA.
  17. -->
  18.  
  19. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  20.                 xmlns:msg="http://www.gnome.org/~shaunm/gnome-doc-utils/l10n"
  21.                 xmlns:math="http://exslt.org/math"
  22.                 extension-element-prefixes="math"
  23.                 version="1.0">
  24.  
  25. <!--!!==========================================================================
  26. Localized Numbers
  27. -->
  28.  
  29. <xsl:include href="gettext.xsl"/>
  30.  
  31.  
  32. <!--**==========================================================================
  33. l10n.number
  34. Formats a number according to a localized numbering system
  35. $value: The numeric value of the number to format
  36. $format: The numbering system to use
  37.  
  38. REMARK: Talk about numbering systems
  39. -->
  40. <xsl:template name="l10n.number">
  41.   <xsl:param name="value"/>
  42.   <xsl:param name="format"/>
  43.   <xsl:choose>
  44.     <xsl:when test="$format='decimal' or $format='1'">
  45.       <xsl:number format="1" value="$value"/>
  46.     </xsl:when>
  47.     <xsl:when test="$format='alpha-lower' or $format='a'">
  48.       <xsl:number format="a" value="$value"/>
  49.     </xsl:when>
  50.     <xsl:when test="$format='alpha-upper' or $format='A'">
  51.       <xsl:number format="A" value="$value"/>
  52.     </xsl:when>
  53.     <xsl:when test="$format='roman-lower' or $format='i'">
  54.       <xsl:number format="i" value="$value"/>
  55.     </xsl:when>
  56.     <xsl:when test="$format='roman-upper' or $format='I'">
  57.       <xsl:number format="I" value="$value"/>
  58.     </xsl:when>
  59.  
  60.     <xsl:when test="$format='cjk-japanese'     or
  61.                     $format='cjk-chinese-simp' or
  62.                     $format='cjk-chinese-trad' ">
  63.       <xsl:call-template name="l10n.number.cjk-ideographic">
  64.         <xsl:with-param name="value" select="$value"/>
  65.         <xsl:with-param name="format" select="$format"/>
  66.       </xsl:call-template>
  67.     </xsl:when>
  68.  
  69.     <xsl:when test="$format='ionic-lower' or $format='ionic-upper'">
  70.       <xsl:call-template name="l10n.number.ionic">
  71.         <xsl:with-param name="value" select="$value"/>
  72.         <xsl:with-param name="format" select="$format"/>
  73.       </xsl:call-template>
  74.     </xsl:when>
  75.  
  76.     <xsl:when test="$format='decimal-arabic'">
  77.       <xsl:call-template name="l10n.number.numeric">
  78.         <xsl:with-param name="value" select="$value"/>
  79.         <xsl:with-param name="digits" select="'Ÿ†Ÿ°Ÿ¢Ÿ£Ÿ§Ÿ•Ÿ¶ŸßŸ®Ÿ©'"/>
  80.       </xsl:call-template>
  81.     </xsl:when>
  82.     <xsl:when test="$format='decimal-persian'">
  83.       <xsl:call-template name="l10n.number.numeric">
  84.         <xsl:with-param name="value" select="$value"/>
  85.         <xsl:with-param name="digits" select="'€∞€±€≤€≥€¥€µ€∂€∑€∏€π'"/>
  86.       </xsl:call-template>
  87.     </xsl:when>
  88.  
  89.     <xsl:when test="$format='alpha-serbian-lower'">
  90.       <xsl:call-template name="l10n.number.alphabetic">
  91.         <xsl:with-param name="value" select="$value"/>
  92.         <xsl:with-param name="alphabet"
  93.                         select="'–∞–±–≤–≥–¥—í–µ–∂–∑–∏—ò–∫–ª—ô–º–Ω—ö–æ–ø—Ä—Å—Ç—õ—É—Ñ—Ö—Ü—á—ü—à'"/>
  94.       </xsl:call-template>
  95.     </xsl:when>
  96.     <xsl:when test="$format='alpha-serbian-upper'">
  97.       <xsl:call-template name="l10n.number.alphabetic">
  98.         <xsl:with-param name="value" select="$value"/>
  99.         <xsl:with-param name="alphabet"
  100.                         select="'–ê–ë–í–ì–î–Ç–ï–ñ–ó–ò–à–ö–õ–â–ú–ù–ä–û–ü–†–°–¢–ã–£–§–•–¶–ß–è–®'"/>
  101.       </xsl:call-template>
  102.     </xsl:when>
  103.  
  104.     <xsl:when test="$format='alpha-thai'">
  105.       <xsl:call-template name="l10n.number.alphabetic">
  106.         <xsl:with-param name="value" select="$value"/>
  107.         <xsl:with-param name="alphabet"
  108.                         select="'‡∏Ň∏LJ∏ч∏á‡∏à‡∏â‡∏ä‡∏ã‡∏å‡∏ç‡∏é‡∏è‡∏ê‡∏ë‡∏í‡∏ì‡∏î‡∏ï‡∏ñ‡∏ó‡∏ò‡∏ô‡∏ö‡∏õ‡∏ú‡∏ù‡∏û‡∏ü‡∏†‡∏°‡∏¢‡∏£‡∏•‡∏߇∏®‡∏©‡∏™‡∏´‡∏¨‡∏≠‡∏Æ'"/>
  109.       </xsl:call-template>
  110.     </xsl:when>
  111.     <xsl:when test="$format='decimal-thai'">
  112.       <xsl:call-template name="l10n.number.numeric">
  113.         <xsl:with-param name="value" select="$value"/>
  114.         <xsl:with-param name="digits" select="'‡πê‡πë‡πí‡πì‡πî‡πï‡πñ‡πó‡πò‡πô'"/>
  115.       </xsl:call-template>
  116.     </xsl:when>
  117.   </xsl:choose>
  118. </xsl:template>
  119.  
  120.  
  121. <!--**==========================================================================
  122. l10n.number.alphabetic
  123. Formats a number using an alphabetic numbering system
  124. $value: The numeric value of the number to format
  125. $alphabet: A string containing the characters of the alphabet to use
  126.  
  127. REMARK: Talk about alphabetic numbering systems
  128. -->
  129. <xsl:template name="l10n.number.alphabetic">
  130.   <xsl:param name="value"/>
  131.   <xsl:param name="alphabet"/>
  132.   <xsl:variable name="length" select="string-length($alphabet)"/>
  133.   <xsl:choose>
  134.     <xsl:when test="$value <= 0">
  135.       <xsl:number format="1" value="$value"/>
  136.     </xsl:when>
  137.     <xsl:otherwise>
  138.       <xsl:variable name="digit">
  139.         <xsl:choose>
  140.           <xsl:when test="$value mod $length = 0">
  141.             <xsl:value-of select="$length"/>
  142.           </xsl:when>
  143.           <xsl:otherwise>
  144.             <xsl:value-of select="$value mod $length"/>
  145.           </xsl:otherwise>
  146.         </xsl:choose>
  147.       </xsl:variable>
  148.       <xsl:if test="$value - $digit != 0">
  149.         <xsl:call-template name="l10n.number.alphabetic">
  150.           <xsl:with-param name="value" select="($value - $digit) div $length"/>
  151.           <xsl:with-param name="alphabet" select="$alphabet"/>
  152.         </xsl:call-template>
  153.       </xsl:if>
  154.       <xsl:value-of select="substring($alphabet, $digit, 1)"/>
  155.     </xsl:otherwise>
  156.   </xsl:choose>
  157. </xsl:template>
  158.  
  159.  
  160. <!--**==========================================================================
  161. l10n.number.numeric
  162. Formats a number using a numeric numbering system with any radix
  163. $value: The numeric value of the number to format
  164. $digits: A string containing the digits to use, starting with zero
  165.  
  166. REMARK: Talk about numeric numbering systems
  167. -->
  168. <xsl:template name="l10n.number.numeric">
  169.   <xsl:param name="value"/>
  170.   <xsl:param name="digits"/>
  171.   <xsl:param name="length" select="string-length($digits)"/>
  172.   <xsl:choose>
  173.     <xsl:when test="$value < 0">
  174.       <!-- FIXME: We need to localize the negative sign -->
  175.       <xsl:text>-</xsl:text>
  176.       <xsl:call-template name="l10n.number.numeric">
  177.         <xsl:with-param name="value" select="math:abs($value)"/>
  178.         <xsl:with-param name="digits" select="$digits"/>
  179.       </xsl:call-template>
  180.     </xsl:when>
  181.     <xsl:otherwise>
  182.       <xsl:variable name="digit" select="$value mod $length"/>
  183.       <xsl:if test="$value - $digit != 0">
  184.         <xsl:call-template name="l10n.number.numeric">
  185.           <xsl:with-param name="value" select="($value - $digit) div $length"/>
  186.           <xsl:with-param name="digits" select="$digits"/>
  187.         </xsl:call-template>
  188.       </xsl:if>
  189.       <xsl:value-of select="substring($digits, $digit + 1, 1)"/>
  190.     </xsl:otherwise>
  191.   </xsl:choose>
  192. </xsl:template>
  193.  
  194.  
  195. <!--**==========================================================================
  196. l10n.number.cjk-ideographic
  197. Formats a number using a CJK ideographic system
  198. $value: The numeric value of the number to format
  199. $format: Which ideographic system to use
  200.  
  201. REMARK: Talk about CJK ideographic numbering systems.  Valid values of ${format}
  202. are #{cjk-japanese}, #{cjk-chinese-simp}, and #{cjk-chinese-trad}.
  203. -->
  204. <xsl:template name="l10n.number.cjk-ideographic">
  205.   <xsl:param name="value"/>
  206.   <xsl:param name="format"/>
  207.   <xsl:call-template name="l10n.number.cjk-ideographic.private">
  208.     <xsl:with-param name="value" select="$value"/>
  209.     <xsl:with-param name="format" select="$format"/>
  210.     <xsl:with-param name="level" select="0"/>
  211.   </xsl:call-template>
  212. </xsl:template>
  213.  
  214. <!--#* l10n.number.cjk-ideographic.private -->
  215. <xsl:template name="l10n.number.cjk-ideographic.private">
  216.   <xsl:param name="value"/>
  217.   <xsl:param name="format"/>
  218.   <xsl:param name="level" select="0"/>
  219.   <xsl:param name="zero" select="true()"/>
  220.   <xsl:variable name="ones">
  221.     <xsl:text>〇一二三四</xsl:text>
  222.     <xsl:text>五六七八九</xsl:text>
  223.   </xsl:variable>
  224.   <xsl:variable name="tens">
  225.     <xsl:text>十百千</xsl:text>
  226.   </xsl:variable>
  227.   <!-- FIXME: pick a upper bound and fallback to decimal -->
  228.   <xsl:variable name="myriads">
  229.     <xsl:choose>
  230.       <xsl:when test="$format='cjk-japanese'">
  231.         <xsl:text>万億兆京垓</xsl:text>
  232.       </xsl:when>
  233.       <xsl:when test="$format='cjk-chinese-simp'">
  234.         <xsl:text>万亿兆</xsl:text>
  235.       </xsl:when>
  236.       <xsl:when test="$format='cjk-chinese-trad'">
  237.         <xsl:text>萬億兆</xsl:text>
  238.       </xsl:when>
  239.     </xsl:choose>
  240.   </xsl:variable>
  241.  
  242.   <xsl:variable name="digit" select="$value mod 10"/>
  243.   <xsl:if test="$value - $digit > 0">
  244.     <xsl:call-template name="l10n.number.cjk-ideographic.private">
  245.       <xsl:with-param name="value" select="($value - $digit) div 10"/>
  246.       <xsl:with-param name="format" select="$format"/>
  247.       <xsl:with-param name="level" select="$level + 1"/>
  248.       <xsl:with-param name="zero" select="$digit = 0"/>
  249.     </xsl:call-template>
  250.   </xsl:if>
  251.   <xsl:choose>
  252.     <xsl:when test="$digit = 0">
  253.       <xsl:choose>
  254.         <xsl:when test="$value = 0">
  255.           <xsl:value-of select="substring($ones, $digit + 1, 1)"/>
  256.         </xsl:when>
  257.         <xsl:when test="$format='cjk-chinese-simp' and not($zero)">
  258.           <xsl:value-of select="substring($ones, $digit + 1, 1)"/>
  259.         </xsl:when>
  260.         <xsl:when test="$format='cjk-chinese-trad' and not($zero)">
  261.           <xsl:value-of select="substring($ones, $digit + 1, 1)"/>
  262.         </xsl:when>
  263.       </xsl:choose>
  264.     </xsl:when>
  265.     <xsl:otherwise>
  266.       <xsl:value-of select="substring($ones, $digit + 1, 1)"/>
  267.     </xsl:otherwise>
  268.   </xsl:choose>
  269.   <xsl:variable name="ten" select="$level mod 4"/>
  270.   <xsl:choose>
  271.     <xsl:when test="$ten != 0">
  272.       <xsl:if test="$digit != 0">
  273.         <xsl:value-of select="substring($tens, $ten, 1)"/>
  274.       </xsl:if>
  275.     </xsl:when>
  276.     <xsl:otherwise>
  277.       <xsl:variable name="myriad" select="($level - $ten) div 4"/>
  278.       <xsl:if test="$myriad != 0">
  279.         <xsl:value-of select="substring($myriads, $myriad, 1)"/>
  280.       </xsl:if>
  281.     </xsl:otherwise>
  282.   </xsl:choose>
  283. </xsl:template>
  284.  
  285.  
  286. <!--**==========================================================================
  287. l10n.number.ionic
  288. Formats a number using the Ionic numeral system
  289. $value: The numeric value of the number to format
  290. $format: Which format to use
  291.  
  292. REMARK: Talk about the Ionic numeral system.  Talk about ${format}
  293. See #{http://en.wikipedia.org/wiki/Greek_numerals}.
  294. -->
  295. <xsl:template name="l10n.number.ionic">
  296.   <xsl:param name="value"/>
  297.   <xsl:param name="format" select="'ionic-lower'"/>
  298.   <xsl:choose>
  299.     <xsl:when test="$value < 1 or $value > 999999">
  300.       <xsl:number format="1" value="$value"/>
  301.     </xsl:when>
  302.     <xsl:otherwise>
  303.       <xsl:call-template name="l10n.number.ionic.private">
  304.         <xsl:with-param name="value" select="$value"/>
  305.         <xsl:with-param name="format" select="'ionic-lower'"/>
  306.         <xsl:with-param name="level" select="1"/>
  307.       </xsl:call-template>
  308.       <xsl:text>¬¥</xsl:text>
  309.     </xsl:otherwise>
  310.   </xsl:choose>
  311. </xsl:template>
  312.  
  313. <!--#* l10n.number.ionic.private -->
  314. <xsl:template name="l10n.number.ionic.private">
  315.   <xsl:param name="value"/>
  316.   <xsl:param name="format" select="'ionic-lower'"/>
  317.   <xsl:param name="level" select="1"/>
  318.   <xsl:param name="stigma" select="false()"/>
  319.   <xsl:variable name="digit" select="$value mod 10"/>
  320.   <xsl:if test="$value - $digit > 0">
  321.     <xsl:call-template name="l10n.number.ionic.private">
  322.       <xsl:with-param name="value" select="($value - $digit) div 10"/>
  323.       <xsl:with-param name="format" select="$format"/>
  324.       <xsl:with-param name="level" select="$level + 1"/>
  325.       <xsl:with-param name="stigma" select="$stigma"/>
  326.     </xsl:call-template>
  327.   </xsl:if>
  328.   <xsl:choose>
  329.     <xsl:when test="$format='ionic-lower'">
  330.       <xsl:choose>
  331.         <xsl:when test="$digit = 0"/>
  332.         <xsl:when test="not($stigma) and $digit = 6 and $level = 1">
  333.           <xsl:text>œÉœÑ</xsl:text>
  334.         </xsl:when>
  335.         <xsl:when test="$level = 1 or $level = 4">
  336.           <xsl:if test="$level = 4">
  337.             <xsl:text>,</xsl:text>
  338.           </xsl:if>
  339.           <xsl:value-of select="substring('Œ±Œ≤Œ≥Œ¥ŒµœõŒ∂Œ∑Œ∏', $digit, 1)"/>
  340.         </xsl:when>
  341.         <xsl:when test="$level = 2 or $level = 5">
  342.           <xsl:if test="$level = 5">
  343.             <xsl:text>,</xsl:text>
  344.           </xsl:if>
  345.           <xsl:value-of select="substring('ŒπŒ∫ŒªŒºŒΩŒæŒøœÄœü', $digit, 1)"/>
  346.         </xsl:when>
  347.         <xsl:when test="$level = 3 or $level = 6">
  348.           <xsl:if test="$level = 6">
  349.             <xsl:text>,</xsl:text>
  350.           </xsl:if>
  351.           <xsl:value-of select="substring('œÅœÉœÑœÖœÜœáœàœâœ°', $digit, 1)"/>
  352.         </xsl:when>
  353.       </xsl:choose>
  354.     </xsl:when>
  355.     <xsl:when test="$format='ionic-upper'">
  356.       <xsl:choose>
  357.         <xsl:when test="$digit = 0"/>
  358.         <xsl:when test="not($stigma) and $digit = 6 and $level = 1">
  359.           <xsl:text>Œ£Œ§</xsl:text>
  360.         </xsl:when>
  361.         <xsl:when test="not($stigma) and $digit = 6 and $level = 1">
  362.           <xsl:text>,Œ£,Œ§</xsl:text>
  363.         </xsl:when>
  364.         <xsl:when test="$level = 1 or $level = 4">
  365.           <xsl:if test="$level = 4">
  366.             <xsl:text>,</xsl:text>
  367.           </xsl:if>
  368.           <xsl:value-of select="substring('ŒëŒíŒìŒîŒïœöŒñŒóŒò', $digit, 1)"/>
  369.         </xsl:when>
  370.         <xsl:when test="$level = 2 or $level = 5">
  371.           <xsl:if test="$level = 5">
  372.             <xsl:text>,</xsl:text>
  373.           </xsl:if>
  374.           <xsl:value-of select="substring('ŒôŒöŒõŒúŒùŒûŒüŒ†œò', $digit, 1)"/>
  375.         </xsl:when>
  376.         <xsl:when test="$level = 3 or $level = 6">
  377.           <xsl:if test="$level = 6">
  378.             <xsl:text>,</xsl:text>
  379.           </xsl:if>
  380.           <xsl:value-of select="substring('Œ°Œ£Œ§Œ•Œ¶ŒßŒ®Œ©œ†', $digit, 1)"/>
  381.         </xsl:when>
  382.       </xsl:choose>
  383.     </xsl:when>
  384.     <xsl:otherwise>
  385.       <xsl:value-of select="$digit"/>
  386.     </xsl:otherwise>
  387.   </xsl:choose>
  388. </xsl:template>
  389.  
  390. </xsl:stylesheet>
  391.